import TableData from "@/components/public/el-table-pagination"; //主页面列表
import TableLyout from '@/components/commonPublic/tableLyoutDetail.vue'
import CustomDialog from "@/components/PhysicalQualityPage/reboundStrengthManage/reboundEntrust/index.vue";
// import CustomDialog1 from "@/components/sampleManage/fieldSampling/index.vue";//取样收样详情
import formJs from "./regexDetail.js"; //新增弹框配置
import {
    getConcreteCheckWitnessPageList, //列表
    submitConcreteCheckWitness, //提交
    delConcreteCheckWitness, //删除
} from "@/api/request.js";
export default {
    name: "reboundEntrustText",
    data() {
        return {
            name: "reboundEntrustText",
            radio: "待办",
            // 列表
            treelength: true, //左侧树显示隐藏
            btnObj: [], //按钮0
            loading: false,
            getList: {
                fCompanyid: "", // 左侧选中组织机构id
                page: 1, // 当前页码
                pageSize: 20, // 每页显示条数
                userId: "", // 查询待办或已办时传 列表页查询不传
                modelType: "0", // 0-待办 1-已办 传2 表示列表页查询  传3表示内嵌查询
                startDates: "", //取样日期开始时间
                endDates: "", //取样日期结束时间
                // taskNumber: "", // 上方查询条件进场编号
            },
            queryCriteriaData: {}, //分页
            table_config: formJs.table_config, //列表
            isShow: false, //是否显示弹框
            // isShow1: false, //取样收样弹框
            // displaySwitching: 3,//非0、1取样&收样；0取样；1收样
            statusNum: null, //点击那个按钮
            dataFid: null, //列表详情id
            currentRow: null, //列表详情
            tableData: [],
            dialogTitle: "",
            userInfo: {}, //登录用户

        };
    },
    components: {
        TableLyout,
        CustomDialog,
        // CustomDialog1,
        TableData, //主页面列表

    },
    created() { },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
        // console.log("this.userInfo", this.userInfo);
        this.getList = {
            fCompanyid: this.userInfo.companyId, // 左侧选中组织机构id
            page: 1, // 当前页码
            pageSize: 20, // 每页显示条数
            userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
            modelType: "0",// 0-待办 1-已办 传2 表示列表页查询  传3表示内嵌查询
            startDates: "", //取样日期开始时间
            endDates: "", //取样日期结束时间
            taskNumber: "", // 上方查询条件进场编号
        };
        this.yj_searchForm(this.getList);
        this.btnRole(this.name);
        this.table_config.operation.cols = [
            {
                prop: "fStatus",
                type: "primary",
                handleRow: this.handleRow,
            },
        ];
        this.table_config.operation["specialClass"] = function (rowData) {
            var color = null;
            if (rowData == "编辑中") {
                color = "red !important";
            } else if (rowData == "已完成") {
                color = "green !important";
            } else {
                color = "#409eff !important";
            }
            return color;
        };
    },
    methods: {
        modelType(e) {
            this.currentRow = "";
            this.dataFid = "";
            if (e == "待办") {
                this.getList.modelType = "0";
            } else {
                this.getList.modelType = "1";
            }
            this.yj_searchForm(this.getList);
        },
        handleRow() { },
        btnRole(name) {
            if (this.userInfo.userId != 'System') {
                var btnList = [];
                var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
                if (ModuleList.length > 0) {
                    ModuleList.map((item) => {
                        if (item.fEncode == name) {
                            btnList = item.modulebuttonList;
                        }
                    });
                    btnList.map(item => {
                        item['disabled'] = false
                    })
                    this.btnObj = btnList
                }
            } else {
                this.btnObj = formJs.btnObj
            }
        },
        getBtnName(name, status) {
            this.statusNum = status;
            this.yj_edit(status)
        },
        // 新增/编辑
        yj_edit(num) {
            this.statusNum = num;
            if (num == 7) {
                if (num == 7) {//查看
                    if (this.dataFid != null) {
                        this.editText();
                        this.dialogTitle = "查看";
                    } else {
                        this.$message.warning("请先选择需要查看的数据");
                    }
                }
            } else {
                if (this.userInfo.companyNature == "总监办") {
                    if (num == 1) { //新增
                        this.editText();
                        this.dialogTitle = "新增";
                    } else if (num == 2) { // 编辑
                        if (this.dataFid != null) {
                            if (this.currentRow.fStatus == "编辑中") {
                                this.editText();
                                this.dialogTitle = "编辑";
                            } else {
                                return this.$message.error('请选择检测状态为"编辑中"的数据！');
                            }

                        } else {
                            this.$message.warning("请先选择需要编辑的数据");
                        }
                    } else if (num == 3) { //提交
                        if (this.dataFid != null) {
                            this.yj_submit(this.currentRow);
                        } else {
                            this.$message.warning("请先选择需要提交的数据");
                        }
                    } else if (num == 4) {//删除
                        if (this.dataFid != null) {
                            this.yj_delete(this.currentRow);
                        } else {
                            this.$message.warning("请先选择需要删除的数据");
                        }
                    }
                } else {
                    this.$message.warning("该功能只有'总监办'可操作");
                }
            }
        },
        // 查看
        editText() {
            this.isShow = true;
        },
        // 点击查看
        yj_viewForm(row, label) {
            this.currentRow = row;
            this.dataFid = row.fId;
            if (label == "委托单编号") {
                this.yj_edit(7);
            }
            // if (label == "取样编号") {
            //     this.statusNum = 7;
            //     this.dialogTitle = "查看";
            //     this.isShow1 = true;
            // }
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val
            this.dataFid = val.fId;
        },
        // 获取列表数据
        yj_searchForm(id) {
            this.loading = true;
            var data = {
                fCompanyid: id.fCompanyid, // 左侧选中组织机构id
                page: id.page, // 当前页码
                pageSize: id.pageSize, // 每页显示条数
                userId: id.userId,// 查询待办或已办时传 列表页查询不传
                modelType: id.modelType, // 0-待办 1-已办 传2 表示列表页查询  传3表示内嵌查询
                startDates: id.startDates, //取样日期开始时间
                endDates: id.endDates,//取样日期结束时间
                // taskNumber: "", // 上方查询条件进场编号
            }
            getConcreteCheckWitnessPageList(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        var that = this;
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        that.queryCriteriaData = res.data.pageInfo;
                    } else {
                        this.$message.error("列表", res.msg);
                        this.loading = false;
                    }
                })
                .catch(() => {
                    this.loading = false;
                    console.log("获取列表数据接口报错");
                });
        },
        // 提交
        yj_submit(row) {
            if (row.fStatus == "编辑中") {
                this.$confirm("是否继续提交?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                })
                    .then(() => {
                        this.loading = true;
                        submitConcreteCheckWitness({
                            fId: row.fId,
                            userId: this.userInfo.userId,
                            userName: this.userInfo.realName,
                        })
                            .then((res) => {
                                if (res.errcode == 0) {
                                    this.loading = false;
                                    this.yj_searchForm(this.getList);
                                    this.$message.success("提交成功");
                                } else {
                                    this.$message.error("提交失败", res.msg);
                                    this.loading = false;
                                }
                            })
                            .catch(() => {
                                console.log("提交失败");
                                this.loading = false;
                            });
                    })
                    .catch(() => {
                        this.$message("取消提交");
                    });

            } else {
                return this.$message.error('请选择检测状态为"编辑中"的数据！');
            }
        },
        // 删除
        yj_delete(row) {
            if (row.fStatus == "编辑中") {
                this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                })
                    .then(() => {
                        this.loading = true;
                        delConcreteCheckWitness({ fId: row.fId })
                            .then((res) => {
                                if (res.errcode == 0) {
                                    this.loading = false;
                                    this.yj_searchForm(this.getList);
                                    this.$message.success("删除成功");
                                } else {
                                    this.$message.error("删除失败", res.msg);
                                    this.loading = false;
                                }
                            })
                            .catch(() => {
                                console.log("删除失败");
                                this.loading = false;
                            });
                    })
                    .catch(() => {
                        this.$message("取消删除");
                    });
            } else {
                return this.$message.error('请选择检测状态为"编辑中"的数据！');
            }
        },
        // 弹框
        refreshList() { //刷新列表
            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            })
        },
        closeDialog() {
            this.isShow = false;
            this.isShow1 = false;
        },
        // 弹框


    },
};